﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WebsiteClient.Models;

namespace WebsiteClient.DB
{
    public class UserDB
    {
        static ApplicationDbContext db = new ApplicationDbContext();

        //public bool AddUser(ApplicationUser user)
        //{
        //    db.User.Add(user);
        //    db.SaveChanges();
            
        //}


        //internal List<Event> GetEventsById(string id)
        //{
        //    var query = from e in db.Events select e;
        //    List<Event> list = new List<Event>();

        //    foreach (var item in query)
        //    {
        //        if (item.ApplicationUser_Id == id)
        //        {
        //            list.Add(item);
        //        }

        //    }
        //    return list;
        //}

        public bool IsEmailAvailable(string email)
        {
            bool isAvailable = false;

            List<ApplicationUser> list = new List<ApplicationUser>();

            var query = from u in db.Users
                        //where u.Email == email 
                        select u;

            foreach (var item in query)
            {
                if (item.Email == email)
                {
                    list.Add(item);
                }
            }

            if (list.Count == 0)
            {
                isAvailable = true;
            }

            return isAvailable;
        }
    }
}
